package com.imooc.coupon.converter;

import com.alibaba.fastjson.JSON;
import com.imooc.coupon.vo.TemplateRule;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @description:
 * @author：naxiaozi，微信：naxiaozi
 * @date: 2025/8/13
 * @Copyright：
 */
@Converter
public class RuleConvert implements AttributeConverter<TemplateRule,String> {
    @Override //转成json
    public String convertToDatabaseColumn(TemplateRule rule) {
        return JSON.toJSONString(rule);
    }

    @Override //转成实体
    public TemplateRule convertToEntityAttribute(String rule) {
        return JSON.parseObject(rule,TemplateRule.class);
    }
}
